package com.vehicle.service.imp;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.vehicle.bean.DataGridView;
import com.vehicle.mapper.CarMapper;
import com.vehicle.mapper.ViolationRecordMapper;
import com.vehicle.pojo.ViolationRecord;
import com.vehicle.service.ViolationRecordService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ViolationRecordServiceImpl implements ViolationRecordService {
    private Logger logger = Logger.getLogger(this.getClass());
    @Autowired
    private ViolationRecordMapper violationRecordMapper;

    @Override
    public DataGridView findViolationRecord(ViolationRecord violationRecord) {
        DataGridView dataGridView = new DataGridView();
        Page page = PageHelper.startPage(violationRecord.getPage(),violationRecord.getLimit());
        List<ViolationRecord> violationRecords=violationRecordMapper.selectViolationRecord(violationRecord);
        dataGridView.setCount(page.getTotal());
        dataGridView.setData(violationRecords);
        return dataGridView;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void deleteViolationRecord(int violationid) {
        violationRecordMapper.updateStatusByViolationId(violationid);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void deleteBatchViolationRecord(Integer[] violationIds) {
        for (Integer violationid:violationIds){
            violationRecordMapper.updateStatusByViolationId(violationid);
        }
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void addViolationRecord(ViolationRecord violationRecord) {
        violationRecordMapper.addViolationRecord(violationRecord);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void updateViolationRecord(ViolationRecord violationRecord) {
        violationRecordMapper.updateViolationRecord(violationRecord);
    }
}
